home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / Files / Education / M / MathPad 2.15 / examples / solve < prev    next >
Encoding:
Text File  |  1993-09-19  |  468 b   |  25 lines  |  [TEXT/MPAD]

  1. -- Solution of a system of equations by Cramers rule.
  2.  
  3. solve(A,B)[j] = det(cram(A,B,j))/det(A)
  4. cram(A,B,k)[i,j] = A[i,j] when j≠k, B[i] dim[count(B)]
  5.  
  6. -- example system of equations
  7. -- 2x +  y +  z = 2
  8. --  x -  y + 5z = 4
  9. --       y -  z = 4
  10.  
  11. A={{ 2, 1, 1},  -- coefficients
  12.    { 1,-1, 5},
  13.    { 0, 1,-1}}
  14.  
  15. C= { 2, 4, 4}   -- constants
  16.  
  17. solve(A,C):{-4.0,7.0,3.0}
  18.  
  19. x=solve(A,C)[1]
  20. y=solve(A,C)[2]
  21. z=solve(A,C)[3]
  22.  
  23. 2*x +  y +   z:2.0
  24.   x -  y + 5*z:4.0
  25.        y -   z:4.0